package com.ruoyi.web.controller.statis;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.statis.domain.KhStatis;
import com.ruoyi.statis.domain.RkStatis;
import com.ruoyi.statis.service.KhStatisService;
import com.ruoyi.statis.service.RkStatisService;
import com.ruoyi.storage.service.RepoWareService;
import com.ruoyi.system.domain.SysCity;
import com.ruoyi.system.domain.SysProvince;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.SysCityService;
import com.ruoyi.system.service.SysProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/statis/Kh")
public class StatisKhController extends BaseController {

    // 方法返回值前缀
    private String prefix = "statis/khstatis";

    @Autowired
    private RepoWareService repoWareService;

    @Autowired
    private ISysUserService iSysUserService;

    @Autowired
    private SysProvinceService sysProvinceService;

    @Autowired
    private KhStatisService khStatisService;


    @Autowired
    private SysCityService sysCityService;

    @RequestMapping("city/{prId}")
    @ResponseBody
    public List<SysCity> getCityById(@PathVariable Long prId) {
        List<SysCity> citys = sysCityService.list(new QueryWrapper<SysCity>().eq("prov_id", prId));
        return citys;
    }

    @RequestMapping()
    public String view(Model model) {
        List<SysProvince> pr = sysProvinceService.list();
        model.addAttribute("prs",pr);
        return  prefix+"/khstatis";
    }

//    @RequiresPermissions("storage:ware:view")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(KhStatis khStatis) {
        startPage();
        List<KhStatis> list = khStatisService.getAllkh(khStatis);
        for ( KhStatis  kh: list ) {
            System.out.println(kh);
        }
        return getDataTable(list);
    }

    /**
     * 查看详情1
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/details/{id}")
    public String details(Model model,@PathVariable("id") String id) {
        model.addAttribute("rid",id);
        return "statis/khstatis/khstatisdetail";
    }

    /***
     * 详情页面id
     * @param
     * @return
     */
    @RequestMapping("/listdetail/{id}")
    @ResponseBody
    public TableDataInfo listdetail(@PathVariable String id) {
        System.out.println("id"+id);
        startPage();
        KhStatis rkStatis1=new KhStatis();
        rkStatis1.setMkcustomerid(Integer.valueOf(id));
        System.out.println(rkStatis1);
        List<KhStatis> list = khStatisService.getAllkh1(rkStatis1);
            System.out.println("------------"+list.get(0));

        return getDataTable(list);
    }


}
